Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(graphcache) - Handle fields with associated GraphQLError as cache misses and provide errors to updaters #1356

Merged
merged 13 commits into from
Feb 4, 2021

Conversation

kitten
Copy link
Member

@kitten kitten commented Feb 2, 2021

Resolve #1344

Summary

This change attempts to improve Graphcache's error handling and error awareness. Instead of ignoring the added information that GraphQLError#path may provide for individual null'ed out fields, Graphcache now processes these errors and dynamically replaces null values (links and records) as it writes them with undefined — i.e. uncached / cache misses — when an associated GraphQLError has been received for a given field.

Set of changes

  • Add Context.__internal.path tracking the current data path via aliases and indices
  • Add Context.__internal.errorMap tracking the current CombinedError's GraphQLErrors by their paths
  • Add Context.error which shows an updater its current field's error if any exists
  • Replace fieldValue in write with undefined rather than null if the current field has an associated error to it

Size change from 6.87kB gzip to 7.07kB gzip (an increase of 0.2kB gzip)

It's not needed to track current errors from results there,
so it can alternatively be fully removed.
When a field has an associated GraphQLError then the `fieldValue` should
be written as `undefined` rather than `null`.
This is to further hide the implementation from the user and
to ensure that sub-write methods like `updateQuery` or `writeFragment`
on the Store don't interfere with this logic as they'd build up their
own paths.
@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2021

🦋 Changeset detected

Latest commit: 6a284f5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@urql/exchange-graphcache Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kitten kitten marked this pull request as ready for review February 2, 2021 12:44
Copy link
Contributor

@wgolledge wgolledge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Definitely a nice upgrade and I'm a big fan of handling errors consistently with undefined

exchanges/graphcache/src/operations/write.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using offlineExchange with storage option using metaData methods swallows errors
3 participants